﻿@{ ViewBag.Title = "Index";
    Layout = "~/Areas/Shared/_LayuiList.cshtml"; }

<!--模糊搜索区域-->
<div class="layui-row">
    <form class="layui-form layui-col-md12 com-search">
    </form>
</div>
<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
<script>
    layui.use(["element", "table", "form", "laydate", "exLayer", "exUtils"], function () {
        let table = layui.table;
        let form = layui.form;
        let laydate = layui.laydate;
        let exLayer = layui.exLayer;
        let exUtils = layui.exUtils;
        laydate.render({
            elem: '#StartEndDate'
            , range: '~'
        });

        let ThisTable = table.render({
            elem: "#tableId",
            url: "/SysBasic/LogonLog/List",
            limit: 10,
            page: true,
            toolbar: "#toolbarTpl",
            cols: [[
                { field: "Account", title: "账户", width: 120, sort: true  },
                { field: "RealName", title: "姓名", width: 120, sort: true  },
                { field: "LogType", title: "登录类型", width: 100, sort: true },
                { field: "Description", title: "描述", sort: true },
                { field: "CreateTime", title: "登录时间", sort: true }
            ]],
            done: function (res, curr, count) {
                console.log(res, curr, count);
            }
        });

        form.on("submit(search)", function (data) {
            ThisTable.reload({
                where: data.field,
                page: { curr: 1 }
            });
            return false;
        });

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "batchDel":
                    batchDel();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "del":
                    del(data.Id);//field Id 和 数据库表字段 Id 要一致
                    break;
            }
        });

        function batchDel() {
            exLayer.confirm("确定要批量删除吗？", function (index) {
                layer.close(index);
                let idsStr = exUtils.tableBatchCheck(table);
                if (idsStr) {
                    exUtils.ajax("/SysBasic/LogonLog/BatchDel", "get", { idsStr: idsStr }, true).done(function (response) {
                        exUtils.tableSuccessMsg(response.message);
                    }).fail(function (error) {
                        console.log(error);
                    });
                }
            });
        }

        function del(id) {
            exLayer.confirm("确定要删除吗？", function () {
                exUtils.ajax("/SysBasic/LogonLog/Delete", "get", { id: id }, true).done(function (response) {
                    exUtils.tableSuccessMsg(response.message);
                }).fail(function (error) {
                    console.log(error);
                });
            })
        }

    })
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
</script>